package com.learn.micro_mall.domain.service.brand;

import com.learn.micro_mall.domain.entity.brand.BrandEntity;
import com.learn.micro_mall.repository.brand.BrandRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class BrandValidatorDomainService {

    @Resource
    private BrandRepository brandRepository;

    public void validatorCreateBrandParam(BrandEntity entity) throws Exception {
        BrandEntity brandEntity = brandRepository.getBrandEntityByBrandName(entity.getBrandId().getBrandName());
        if(brandEntity != null){
            throw new Exception("已经存在该品牌,不需要重复创建");
        }
    }

    public void validatorBrandHasExist(String brandName) throws Exception {
        BrandEntity brandEntity = brandRepository.getBrandEntityByBrandName(brandName);
        if(brandEntity == null){
            throw new Exception("不存在该品牌");
        }
    }
}
